//
// Created by xili on 2024/9/2 14:18.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    long long minSum(vector<int> &nums1, vector<int> &nums2) {
        long long s1 = 0;
        bool have1 = false;
        int n1 = nums1.size();
        for (int i = 0; i < n1; i++) {
            if (nums1[i] == 0) {
                have1 = true;
                s1++;
            } else {
                s1 += nums1[i];
            }
        }
        long long s2 = 0;
        bool have2 = false;
        int n2 = nums2.size();
        for (int i = 0; i < n2; i++) {
            if (nums2[i] == 0) {
                have2 = true;
                s2++;
            } else {
                s2 += nums2[i];
            }
        }
        if ((s1 < s2 && !have1) || (s1 > s2 && !have2)) {
            return -1;
        }
        return max(s1, s2);
    }
};